package top.infopub.mgr.mkt.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.infopub.mgr.mkt.dao.BidReviewDao;
import top.infopub.mgr.mkt.domain.BidCurrencyDomain;
import top.infopub.mgr.mkt.service.BidReviewService;
import top.infopub.mgr.mkt.vo.BidCurrencyVo;
import top.infopub.model.mkt.BidReview;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Author Warking
 * @Date 2021/4/28 19:30
 * @Version 1.0
 */
@Service
public class BidReviewServiceImpl implements BidReviewService {
    @Autowired
    private BidReviewDao bidReviewDao;

    @Override
    public Page<BidCurrencyDomain> selectPage(Page<BidCurrencyDomain> page, BidCurrencyVo bidCurrencyVo) throws ParseException {
        //处理时间范围
        if (!StringUtils.isEmpty(bidCurrencyVo.getDates())) {
            String[] splitTime = bidCurrencyVo.getDates().split("~");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            bidCurrencyVo.setStartDate(format.parse(splitTime[0]));
            bidCurrencyVo.setEndDate(format.parse(splitTime[1]));
        }
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<BidCurrencyDomain>) bidReviewDao.selectByDomainWhere(bidCurrencyVo);
    }

    @Override
    public BidReview selectById(String id) {
        return bidReviewDao.selectByPrimaryKey(id);
    }

    @Override
    public List<BidReview> queryByProCode(String proCode) {
        return bidReviewDao.queryByProCode(proCode);
    }
}
